package 代码记录.指定公司代码练习记录.备战快手;

/**
 * @author zx
 * @create 2023-05-13 12:01
 */
public class 合并两个有序数组_88 {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        if(nums2.length == 0 || n == 0) return;
        int[] temp = new int[m];
        for(int i = 0;i < m;i++){
            temp[i] = nums1[i];
        }
        int i = 0,j = 0;
        int count = 0;
        while(i != m && j != n){
            if(temp[i] <= nums2[j]){
                nums1[count] = temp[i];
                i++;
            }else{
                nums1[count] = nums2[j];
                j++;
            }
            count++;
        }
        if(i == m){
            for(int k = j;k < nums2.length;k++){
                nums1[count] = nums2[k];
                count++;
            }
        }else{
            for(int k = i;k < temp.length;k++){
                nums1[count] = temp[k];
                count++;
            }
        }
    }
}
